package com.jp.knowledge.util;

import com.jp.knowledge.model.TabModel;

import java.util.List;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
/**
 * Created by jiayen on 17/6/2.
 */

public class TabDateUtil {
    static DateFormat  format = new SimpleDateFormat("yyyyMMdd");
    private static String[] weekDays= {"周日","周一","周二","周三","周四","周五","周六"};
    public static List<TabModel> getDays(){

        List<TabModel> list = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
//			calendar.add(Calendar.DAY_OF_YEAR, 1);

        calendar.add(Calendar.DAY_OF_YEAR, -1);
        add(list, calendar, "昨天",false);
        calendar.add(Calendar.DAY_OF_YEAR,1);
        add(list, calendar, "今天",false);
        calendar.add(Calendar.DAY_OF_YEAR,1);
        add(list, calendar, "明天",false);


        calendar.add(Calendar.DAY_OF_YEAR,-2);
        for (int i = 0; i < 5; i++) {
            calendar.add(Calendar.DAY_OF_YEAR,-1);
            int  weekDay = calendar.get(Calendar.DAY_OF_WEEK)-1;
            add(list, calendar, weekDays[weekDay],true);
        }
        return list;
    }
    public static void add(List<TabModel> list, Calendar calendar, String name, int  position){
        TabModel tabModel = new TabModel();
        tabModel.setDate(format.format(calendar.getTime()));
        tabModel.setName(name);
        list.add(position,tabModel);

    }

    public static String format(Date date){
        DateFormat  format = new SimpleDateFormat("yy年MM月dd日");
        return    format.format(date);
    }
    public static void add(List<TabModel> list,Calendar calendar,String name,boolean  first){
        TabModel tabModel = new TabModel();
        tabModel.setDate(format.format(calendar.getTime()));
        tabModel.setName(name);
        if(first){
            list.add(0,tabModel);
        }else {
            list.add(tabModel);
        }

    }

}
